package com.rzz.overalldemo.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @description:
 * @author: ruanzhizhi
 * @date: 2021/7/15 15:25
 */
@RestController
@Slf4j
public class TestController {

    @Autowired
    private RedisTemplate redisTemplate;

    @GetMapping("/hello")
    public String hello() {
        Date date = new Date();
        log.error("error---5---" + date);
        log.warn("warn---4---" + date);
        log.info("info---3---" + date);
        log.debug("debug---2---" + date);
        log.trace("trace---1---" + date);
        return "hello";
    }

    @GetMapping("/redis_set")
    public String redisSet() {
        ValueOperations valueOperations = redisTemplate.opsForValue();
        valueOperations.set("name", "rzz");
        return "success";
    }

    @GetMapping("/redis_get")
    public String redisGet() {
        ValueOperations valueOperations = redisTemplate.opsForValue();
        String name = (String) valueOperations.get("name");
        return name;
    }
}
